package cn.usian.controller;

import cn.usian.common.R;
import cn.usian.pojo.Goods;
import cn.usian.service.GoodsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**
     *查询所有
     * @return
     */
    @GetMapping("/page")
    public R findPage(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "5")Integer pageSize,String name){
        Page<Goods>page1=goodsService.findPage(page,pageSize,name);
        return R.success(page1);
    }

    /**
     * 添加
     * @param goods
     * @return
     */
    @PostMapping
    public R add(@RequestBody Goods goods){
        return goodsService.add(goods);
    }

    @GetMapping("{id}")
    public R findById(@PathVariable Integer id){
        return goodsService.findById(id);
    }
    /**
     * 修改
     * @param goods
     * @return
     */
    @PutMapping
    public R update(@RequestBody Goods goods){
        return goodsService.update(goods);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public R delete(String ids ){
        return goodsService.delete(ids);
    }
    /**
     * 启动-禁用
     * @param ids
     * @param status
     * @return
     */
    @PostMapping("status/{status}")
    public R editStatus1(String ids,@PathVariable Integer status){
        return goodsService.editStatus(ids,status);
    }
    /**
     * 提交-未提交
     * @param ids
     * @param status
     * @return
     */
    @GetMapping("status/{status}")
    public R updateStatus2(String ids,@PathVariable Integer status){
        return goodsService.updateStatus2(ids,status);
    }

    /**
     * 上架-下架
     * @param ids
     * @param status
     * @return
     */
    @PutMapping("status/{status}")
    public R updateStatus3(String ids,@PathVariable Integer status){
        return goodsService.updateStatus3(ids,status);
    }
}
